package com.huike.web.controller.review;


import com.huike.common.core.controller.BaseController;
import com.huike.common.core.domain.AjaxResult;
import com.huike.review.pojo.PageBean;
import com.huike.review.pojo.Review;
import com.huike.review.service.ReviewService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.parameters.P;
import org.springframework.web.bind.EscapedErrors;
import org.springframework.web.bind.annotation.*;

/**
 * 该Controller主要是为了复习三层架构以及Mybatis使用的，该部分接口已经放开权限，可以直接访问
 * 同学们在此处编写接口通过浏览器访问看是否能完成最简单的增删改查
 */
@RestController
@RequestMapping("/review")
public class MybatisReviewController extends BaseController {

    @Autowired
    private ReviewService reviewService;


  @GetMapping("/saveData/{name}/{age}/{sex}")
    public AjaxResult SaveData(@PathVariable String name,@PathVariable Integer age,@PathVariable String sex){
      int row = reviewService.addreview(name,age,sex);
      if (row>0) {
         // return AjaxResult.success("成功插入一条数据",200);
          return  AjaxResult.success();
      }else {
            return AjaxResult.error();
      }
  }

    /**=========================================================修改数据=============================================*/
    @PostMapping("/update")
    public AjaxResult Update(@RequestBody Review review){
        int row = reviewService.update(review);
        if (row>0) {
            return  AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @DeleteMapping("/remove/{id}")
    public AjaxResult deleteById(@PathVariable Long id){
        int row = reviewService.deleteById(id);
        if (row>0) {
            return  AjaxResult.success();
        }else {
            return AjaxResult.error();
        }
    }

    @GetMapping("/getById")
    public AjaxResult selectById(Long id){
        Review review= reviewService.selectById(id);
   return AjaxResult.success(review);
    }

    @GetMapping("/getDataByPage")
    public AjaxResult findPage(Integer pageNum,Integer pageSize ){

        System.out.println(pageNum+pageSize);

        PageBean pageBean = reviewService.findPage(pageNum, pageSize);

        return AjaxResult.success(pageBean);
    }

}
